import { param2Obj } from '@/utils'

const userMap = {
  admin: {
    roles: ['admin'],
    token: 'admin',
    introduction: '我是超级管理员',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  editor: {
    roles: ['editor'],
    token: 'editor',
    introduction: '我是编辑',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  },
  asdasd:{
    data: {
        access_token: "cb81d25de5fa4795b736512ae37b4b27.2c9080b666ed3bc60166ed3bf3ca003a.web",
        token_type: "bearer",
        userInfo: {
            user: {
                id: "2c9080b666ed3bc60166ed3bf3ca001a",
                del: false,
                createdTime: "2018-11-07 16:13:41",
                updatedTime: "2018-11-07 16:13:41",
                username: "asdasd",
                nickname: "许工",
                headUrl:"https://wpimg.wallstcn.com/0e03b7da-db9e-4819-ba10-9016ddfdaed3",
                identityCard:"32011111111",
                mobile:"13131313",
                position:"员工",
                realName:"许123",
                company: {
                  id: "2c9080b666ed3bc60166ed3bf3160016",
                  del: false,
                  createdTime: "2018-11-07 16:13:41",
                  updatedTime: "2018-11-07 16:13:41",
                  companyName: "水泥公司"
                },
                department: {
                    id: "2c9080b666ed3bc60166ed3bf3400017",
                    del: false,
                    createdTime: "2018-11-07 16:13:41",
                    updatedTime: "2018-11-07 16:13:41",
                    departmentName: "生产部"
                }
            },
            roleList: [{
                id: "2c9080b666ed3bc60166ed3bf2d00011",
                del: false,
                createdTime: "2018-11-07 16:13:41",
                updatedTime: "2018-11-07 16:13:41",
                roleName: "超级管理员",
                roleCode: "superadmin",
                fixation: true
            }, {
                id: "2c9080b666ed3bc60166ed3bf2f20013",
                del: false,
                createdTime: "2018-11-07 16:13:41",
                updatedTime: "2018-11-07 16:13:41",
                roleName: "普通用户",
                roleCode: "ordinary",
                fixation: true
            }]
        }
    },
    code: 0,
    message: "成功"
}
}

export default {
  loginByUsername: config => {
    console.log(config)
    const { username } = JSON.parse(config.body)
    return userMap[username]
  },
  getUserInfo: config => {
    const { token } = param2Obj(config.url)
    if (userMap[token]) {
      return userMap[token]
    } else {
      return false
    }
  },
  logout: () => 'success'
}
